#ifndef _M_THREAD_H_
#define _M_THREAD_H_

#include <QObject>
#include <QThread>
//#include <QByteArray>
//#include <QDebug>
//#include "mera_queue_cxx32bit.h"
//#include "mdebug.h"

// 构造一个线程父类,用于提供线程的控制操作
class mThread : public QThread
{
    Q_OBJECT
public:
    explicit mThread(QObject *parent = nullptr) : QThread(parent)
    {
        ;//hid = nullptr;
        set_stop();
    }
    ~mThread()
    {
        StopThread();
    }

protected:
    virtual void run() override
    {
        /* ... here is the expensive or blocking operation ... */
        setup();
        //while(0==stop) loop();
        while(0==isexit()) loop();
        quit();
    }
    virtual void setup(void)
    {
        /* ... here is the expensive or blocking operation ... */
    }
    virtual void loop(void)
    {
        /* ... here is the expensive or blocking operation ... */
    }

public:
    static void StopThread(void) { stop = 1;}
    int isrun(void)
    {
        if((0==stop) && (1==is_run)) return 1;
        return 0;
    }
    // 线程退出标志
    int isexit(void)
    {
        return stop;
    }
    void set_run(void) { is_run = 1; }
    void set_stop(void) { is_run = 0; }

signals:
    void signals_progress(int progress, QString des);
    void signals_update(void);

private:
//protected:
    static int stop;
    int is_run;
};

#endif // _M_THREAD_H_
